<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/icon.css"/>">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/yzr_style.css"/>">

<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
<title>耗材验收</title>
</head>
<body>
<!--  <script type="text/javascript">
	var editIndex_YS_LMB = undefined;
	
	//结束正在编辑的行
	function endEditing_YS_LMB(){
		if (editIndex_YS_LMB == undefined){return true}		
		if ($('#lmb-checkCouPur-dg').datagrid('validateRow',editIndex_YS_LMB)){			
			$('#lmb-checkCouPur-dg').datagrid('endEdit', editIndex_YS_LMB);
			
			editIndex_YS_LMB = undefined;
			return true;
		} else {
			return false;
		}
	}
	
	//事件：单击单元格的事件
	function onClickCell_YS_LMB(index, field){	
		if (editIndex_YS_LMB != index){
			
			if (endEditing_YS_LMB()){			
				$('#lmb-checkCouPur-dg').datagrid('selectRow', index).datagrid('beginEdit', index);
				var ed = $('#lmb-checkCouPur-dg').datagrid('getEditor', {index:index,field:field});
				if (ed){
					($(ed.target).data('textbox') ? $(ed.target).textbox('textbox') : $(ed.target)).focus();
				}
				editIndex_YS_LMB = index;
				
			} else {	
				setTimeout(function(){
					$('#lmb-checkCouPur-dg').datagrid('selectRow', editIndex);
				},0);
			}
		}		
			
			
	}
	
	//结束编辑，同步数据
	function onEndEdit_Ys(index, row){
		var ed = $(this).datagrid('getEditor', {
			index: index,
			field: 'pdNum'
		});		
		row['pdNum'] = $(ed.target).numberspinner('getText');
	}
	
	
	function accept_ys_LMB(){
		if (endEditing_YS_LMB()){
			//$('#lmb-checkCouPur-dg').datagrid('acceptChanges');
			//endEditing_YS_LMB();		
		}
	}

	
	//撤销
	function reject_ys_LMB(){
		$('#lmb-checkCouPur-dg').datagrid('rejectChanges');
		editIndex_YS_LMB = undefined;
	}
	
	//获取数据
	function getChanges(){
		var rows = $('#lmb-checkCouPur-dg').datagrid('getChanges');
		alert(rows.length+' rows are changed!');
	}
	
</script>-->

<script type="text/javascript">
	$(function(){
		var dingId = undefined;
		//打开面板
		$("#lmb-openpanel-btn").linkbutton({
			onClick: function(){
				$("#lmb-selectOrder-panel").window("open");				
				$("#tb-couPurorder-selOrder").datagrid({
		    		url: 'to_lmb_findAllCouPurNoCheck', 
		    		method: 'get',
		    		page:1, 
	    			rows:100
		    	});
			}
		});
		
		//选择订单
		$("#lmb-ok-btn").linkbutton({onClick: function(){
			var rows = $("#tb-couPurorder-selOrder").datagrid("getSelections");
			if(rows.length == 1){
				var cpId = rows[0].cpId;
				var cpStatus = rows[0].cpStatus;
				if(cpStatus == '已验收'){
					$.messager.alert("提示", "该订单已验收，不能重复验收！");
				}else{
					$("#lmb-selectOrder-panel").window("close");
					$("#lmb-cgorder-input").textbox("setValue",cpId);
					var cpId = undefined;
				}				
			}else{
				$.messager.alert("提示", "您还没有选择记录！");
			}
		}});
		
		//模糊查询
		$('#lmb-selOrder-search').searchbox({
		    searcher:function(value,name){
		    	if(value == ''){
		    		$.messager.alert("提示", "请输入查询条件！");
		    	}else{
		    		$("#tb-couPurorder-selOrder").datagrid({	    		
			    		url:'to_lmb_findCgCouPurByIf',
			    		method: 'post', 
			    		queryParams: {
			    			page:1, 
			    			rows:100,
			    			name: name,
			    			value: value,
			    	}});
			    	$('#lmb-selOrder-search').searchbox('setValue', '');
		    	}	    			    	
		    }		    
		}); 
		
		//显示全部
		$("#lmb-selOrder-reload").linkbutton({onClick:function(){
			$("#tb-couPurorder-selOrder").datagrid({
	    		url: 'to_lmb_findAllCgCouPur', 
	    		method: 'get'
	    	});
		}});
		
		//根据日期段查询
		$("#lmb-ok-search").linkbutton({onClick:function(){
			
			var start = $("#lmb-selOrder-startDate").datebox("getValue");
			var end = $("#lmb-selOrder-endDate").datebox("getValue");
			
			if(start == '' || end == ''){
				$.messager.alert("提示", "请选择日期！");
			}else{
				$("#tb-couPurorder-selOrder").datagrid({
		    		url: 'to_lmb_findByJCaiGouDate', 
		    		method: 'post',
		    		queryParams: {
		    			startDate: start,
		    			endDate: end
		    	}});
				$('#lmb-selOrder-startDate').datebox('setValue', '');
				$('#lmb-selOrder-endDate').datebox('setValue', '');
			}			
		}});
		
		//根据采购id查找出采购详情
		$("#lmb-cgorder-input").textbox({
			onChange: function(newValue, oldValue){				
				 $("#lmb-checkCouPur-dg").datagrid({
					url:'to_lmb_findPurDetByPdcpId',
					width: '100%',
					queryParams:{						
						pdId: newValue,
		    			page:1, 
		    			rows:100
					}
				});
			}
		});
		
		// 提交数据
		$("#lmb-checkCouPur-submit").linkbutton({onClick: function(){		
			var orderId = $("#lmb-cgorder-input").textbox("getValue");
			var staffId = $("#lmb-checkCouPur-staff").combogrid("getValue");
			var checkDate = $("#lmb-checkCouPur-date").datebox("getValue");
			
			var rows = $('#lmb-checkCouPur-dg').datagrid('getRows');		
			console.log(JSON.stringify(rows));
			//pdBatchNum,pdNorms,pdPrice,pdNum,supName
			for(var i = 0; i < rows.length; i ++){
				generateHiddenLmb_hy_edit(rows[i], "pdId", i);				
				generateHiddenLmb_hy_edit(rows[i], "pdNum", i);
			}										
			var lmb_checkCouPur_form = $("#lmb_checkCouPur_form");
			lmb_checkCouPur_form.form('submit', {
				url: 'to_lmb_submitCheckMed',				
			    onSubmit: function(){
			    	return $(this).form("validate");
			    },
			    success:function(data){
			    	$.messager.alert('提示', "验收成功");
					$(this).form("clear");
					$('#lmb-checkCouPur-dg').datagrid('loadData', { total: 0, rows: [] }); 
			    }
		  
			});
		}});
		
		function generateHiddenLmb_hy_edit(row, name, i){
			var lmb_checkCouPur_form = $("#lmb_checkCouPur_form");
			//type='hidden'
			$("<input type='hidden' x='y'>")
				.attr("name", "purchaseDetail[" + i + '].'  + name)
				.val(row[name])
				.appendTo(lmb_checkCouPur_form);
		}
		
	});
	
</script>
	
	<!-- 验收单数据 -->
	<form id="lmb_checkCouPur_form" method="post" style="margin-top:0px;">
	<table width="100%" style="background: rgb(236,243,255); padding: 10px; border-radius: 5px;">
		<tr>
			<td style="width:50%;">
				<input id="lmb-cgorder-input" name="materialAcceptance.matCpId"class="easyui-textbox" data-options="required:true,width: '60%',labelAlign:'right',label:'采购单'"/>
				<a id="lmb-openpanel-btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'",style="align:'left'">查找</a>
			</td>
			<td style="width:50%;">
				<select  name="materialAcceptance.matPeople" class="easyui-combogrid" id="lmb-checkCouPur-staff"
				data-options="
					label: '验收人',
					labelAlign:'right',
					required:true,
					width: '60%',
					panelWidth: '290',
					panelHeight: 'auto',				
					url: 'queryAllStaff',
					pagination: true,
					pageSize: 8,
					pageList: [8, 16, 24, 32],
					idField: 'staffNo',
					textField: 'staffName',
					columns: [[
						{field:'staffName',title:'姓名',width:100},
						{field:'departmentName',title:'部门',width:100},
						{field:'postName',title:'职务',width:85}
					]]
				"></select>
			</td>
		</tr>
		<tr>
			
		<td><input name="materialAcceptance.matDate" class="easyui-datebox" id="lmb-checkCouPur-date" data-options="width:'60%',required:true,labelAlign:'right',label:'验收日期'">	</td>
		</tr>
		<!-- 
			<input class="easyui-datebox" id="lmb-checkCouPur-date" data-options="width:'300',required:true,labelAlign:'right',label:'验收日期'">	
			
				<a id="lmb-openpanel-btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查找</a>
			<select class="easyui-combogrid" id="lmb-checkCouPur-staff"
				data-options="
					label: '验收人',
					labelAlign:'right',
					required:true,
					width: '300',
					panelWidth: '290',
					panelHeight: 'auto',
					url: 'queryAllStaff',
					pagination: true,
					pageSize: 8,
					pageList: [8, 16, 24, 32],
					idField: 'staffNo',
					textField: 'staffName',
					columns: [[
						{field:'staffName',title:'姓名',width:100},
						{field:'departmentName',title:'部门',width:100},
						{field:'postName',title:'职务',width:85}
					]]
			"></select>
			<input class="easyui-datebox" id="lmb-checkCouPur-date" data-options="width:'300',required:true,labelAlign:'right',label:'验收日期'">				 -->
	</table>
		
		<!-- 订单明细 -->
		<div style="margin: 5px;"><!-- 	onClickCell:onClickCell_YS_LMB,	
								onEndEdit:onEndEdit_Ys, -->
			<div id="lmb-checkCouPur-tabs" class="easyui-tabs" style="width:100%; margin-top:20px;" 
				data-options="plain:true,narrow:true">
				
				<div title="采购明细" style="padding:10px;">
					<table id="lmb-checkCouPur-dg" class="easyui-datagrid" 
							data-options="
								iconCls: 'icon-edit',									
								width: '100%',
								pagination: true,
								singleSelect: true,
							
								toolbar: '#lmb_ys_tb1',							
								pageSize: 8,
								pageList: [8, 16, 24, 32],
								">
							<thead>
								<tr>	
									<th data-options="field:'pdId',width:'20%',align:'center'">采购订单明细编号</th>			
									<th data-options="field:'pdCId',width:'18%',
										formatter:function(value,row){
											return row.pdName;
										}
									">耗材名称</th>
									<th data-options="field:'pdBatchNum',width:'11%',align:'center'">批号</th>
									<th data-options="field:'pdNorms',width:'11%',align:'center'">单位</th>
									<th data-options="field:'pdPrice',width:'11%',align:'center'">单价</th>
									<th data-options="field:'pdNum',width:'11%',align:'center',editor:{
										type:'numberspinner',
										options:{
											min:0,
											precision:0,
											required:true
										}
									}">数量</th>
									<th data-options="field:'supName',width:'18%',align:'center'">供应商</th>
									<!-- <th data-options="field:'sfhg',width:'2%',idField:'purchOrderDetId',checkbox:true">是否合格</th> -->
								</tr>
							</thead>
					 </table>
					
				</div>							
			</div>						
		</div>
		<!-- 确认按钮 -->
		<a id="lmb-checkCouPur-submit" class="easyui-linkbutton" style="margin-top:10px;margin-left:10px;algin:right;" data-options="iconCls:'icon-ok'">提交</a>
	
	</form>
	
	
	<!-- 选择订单窗口 -->
	<div id="lmb-selectOrder-panel" class="easyui-window" title="选择采购订单" style="width:800px;height:350px;" data-options="closable:true,closed:true,collapsible:false,minimizable:false,maximizable:false">
		<table id="tb-couPurorder-selOrder" class="easyui-datagrid" 
			data-options="
				url:'',				
				fit:true,
				pagination: true,
				pageSize: 8,
				pageList: [8, 16, 24, 32],
				rownumbers: false,
				toolbar: '#lmb-toolbar-selOrder',
				border:false,
				singleSelect:true
				">
			<thead>
				<tr>	
				<th data-options="field:'',width:'5%',checkbox:true,align:'center',editor:'textbox'">订单编号</th>	
				<th data-options="field:'cpId',width:'20%',align:'center',editor:'textbox'">订单编号</th>							
				<th data-options="field:'cpPlId',width:'20%',align:'center'">计划单号</th>	
				<th data-options="field:'name',width:'15%',align:'center'">采购人</th>											
				<th data-options="field:'cpTime',width:'15%',
									formatter:function(value){
					                          var date = new Date(value);  
					                          return date.toLocaleDateString();},align:'center'"
				>采购日期</th>				
				<!-- <th data-options="field:'purchOrderMoney',width:'11%',align:'center'">订单金额</th> -->
				<th data-options="field:'cpStatus',width:'14%',
					styler:function(value,row,index){ 
						if(row.cpStatus == '未验收'){
							return 'color:red;';
						}},
	               align:'center'
                 ">验收状态</th>					                          
				<th data-options="field:'cpRsStatus',width:'14%',align:'center'">是否入库</th>					
				</tr>
			</thead>
		</table>				    
	    
	    <!-- 工具栏 -->
	    <div id="lmb-toolbar-selOrder">
	    	<input id="lmb-selOrder-search" class="easyui-searchbox" data-options="menu: '#lmb-serch', width: '220px',prompt: '请输入关键字'"/>    	
	    	<a id="lmb-selOrder-reload" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true,width: '80px'">刷新</a>
	    	<input id="lmb-selOrder-startDate" class="easyui-datebox" data-options="width:'15%'" /> -
	    	<input id="lmb-selOrder-endDate" class="easyui-datebox" data-options="width: '15%'"/>
	    	<a id="lmb-ok-search" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</a>
	    	<a id="lmb-ok-btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true," style="margin-left:80px;">确定</a>
	    	
	    </div>
	    	    
	    <!-- 搜索框 -->
	    <div id="lmb-serch" style="width:120px">
	    	<div data-options="name:'orderId'">订单编号</div>
	    	<div data-options="name:'name'">采购人</div>
		    <div data-options="name:'checkState'">验收状态</div>
		    <div data-options="name:'rukuState'">是否入库</div>
		</div>		
	</div>	
		
</body>
</html>